<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/4/24/024
 * Time: 20:12
 */

namespace app\admin\validate;

class TaskRecordValidate extends \think\Validate
{

    const SCENE_REMOVE = 'remove'; //删除数据
    const SCENE_CHECK = 'check'; //审核
    const SCENE_CLOSE = 'close'; //审核




    protected $rule = [
        'id' => 'require|number',
        'type_id' => 'require|number',
        'title' => 'require|max:50',
        'total_num'  =>  'require|integer|>:0',
        'award' => 'require|gt:0|_isNumber',
        'info' => 'require|max:50',
    ];


    protected $message  = [
        'type_id.require' => '任务类型必须',
        'type_id.number' => '任务类型必须为数字',
        'title.require' => '标题必须',
        'title.max' => '标题最大长度50',
        'total_num.require' => '数量必须',
        'total_num.integer' => '数量必须为整数',
        'total_num.gt' => '数量必须大于0',
        'award.require' => '奖励金额必填',
        'award.gt' => '奖励金币必须大于0',

    ];
    
    //场景
    protected $scene  = [
       self::SCENE_REMOVE => ['id'],
       self::SCENE_CHECK => ['id'],
       self::SCENE_CLOSE => ['id', 'info'],
    ];
    
    
    /**
    * 验证奖励为小数或整数
    */
    public function _isNumber($val){
        $reg = "/^(([0-9]+|0)\.([0-9]{1,2})$)|^([0-9]+|0)$/";
        return preg_match($reg, $val) ? true : '请输入合法的数字';
    }
    

}